package com.icinfo.cloud.provider.punish.ucase.casemain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：责令整改方式枚举
 *
 * @Author zhengqiang
 * @Date 2022/6/23 21:16
 **/
@AllArgsConstructor
@Getter
public enum CorrectWayEnum {
    /**
     * 责令整改方式枚举
     */
    IMMEDIATELY_CORRECT("1", "立即改正"),
    TIME_CORRECT("2", "限期改正"),
    OTHER_CORRECT("3", "其他");


    /**
     * 编码
     */
    private String code;
    /**
     * 描述
     */
    private String des;

    /**
     * 描述：根据code获取value
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (CorrectWayEnum e : CorrectWayEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return code;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (CorrectWayEnum e : CorrectWayEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
